export const deepTree = (list) => {
  //0.定义一个最终的结果集合
  const result = [];
  //1.先定义一个result映射
  const mapList = {};
  //2.遍历数组追加到result中
  for (let item of list) {
    mapList[item.id] = { ...item };
  }
  //3.遍历数组
  for (let item of list) {
    //根据item.parentId来决定当前item是属于谁的子级
    if (!item.parentId) {
      //如果item.parentId为null表示一级菜单,直接push进result
      result.push(mapList[item.id]); //mapList[item.id]===item
    } else {
      if (mapList[item.parentId].children) {
        mapList[item.parentId].children.push(mapList[item.id]);
      } else {
        mapList[item.parentId].children = [mapList[item.id]];
      }
    }
  }
  return result;
};
